//
//  YSGMyopiaRecordListCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/1/5.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

protocol YSGMyopiaRecordListCellDelegate: NSObjectProtocol {
    func cancelReserve(cell: YSGMyopiaRecordListCell)
}

class YSGMyopiaRecordListCell: UITableViewCell {
    
    weak var delegate: YSGMyopiaRecordListCellDelegate?
    
    func configure(with vm: YSGMyopiaRecordDetailViewModel) {
        titleLabel.text = vm.model.checkItem
        nameLabel.attributedText = vm.name
        numberLabel.attributedText = vm.recordNumber
        positionLabel.text = vm.recordPosition
        timeLabel.text = vm.reserveTime
        hospitalLabel.text = vm.hospitalName
        
        cancelButton.isEnabled = vm.canCancel
        cancelButton.backgroundColor = vm.canCancel ? .main : .background
    }
    
    @IBAction private func cancelReserve() {
        delegate?.cancelReserve(cell: self)
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = 16
            containerView.setShadow()
        }
    }
    
    @IBOutlet private weak var titleLabel: UILabel!
    @IBOutlet private weak var numberLabel: UILabel!
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var positionLabel: UILabel!
    @IBOutlet private weak var timeLabel: UILabel!
    @IBOutlet private weak var hospitalLabel: UILabel!
    
    @IBOutlet private weak var cancelButton: UIButton! {
        didSet {
            cancelButton.layer.cornerRadius = cancelButton.height / 2
        }
    }
}
